console.log(''); // 后台运行时先打印一个空行，优化命令行的显示
const express = require('express')
const cors = require('cors')
require('./env');
const routers = require('./routers')
const app = express()
app.use(cors())
app.use(function (req, res, next) {
  console.log(req.headers.host)
  const startTime = Date.now()
  next()
  console.log(`${req.ip}, ${req.protocol}${req.hostname}${req.originalUrl}: 请求响应耗时${Date.now() - startTime}ms`)
})
app.use(routers)

const server = app.listen(3000, () => {
  const host = server.address().address
  const port = server.address().port
  console.log('server is listening at http://%s:%s', host, port)
})